{% extends 'base/base1.html' %}

{% block title %}{% if object %}编辑图片{% else %}添加图片{% endif %}{% endblock %}

{% block main %}
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-6">
            <div class="card">
                <div class="card-header">
                    <h4>{% if object %}编辑图片{% else %}添加图片{% endif %}</h4>
                </div>
                <div class="card-body">
                    <form method="post" enctype="multipart/form-data">
                        {% csrf_token %}
                        <div class="form-group">
                            <label for="{{ form.product.id_for_label }}">选择商品</label>
                            {{ form.product }}
                            {% if form.product.errors %}
                                <div class="text-danger">{{ form.product.errors }}</div>
                            {% endif %}
                        </div>
                        <div class="form-group">
                            <label for="{{ form.image.id_for_label }}">图片</label>
                            {{ form.image }}
                            {% if form.image.errors %}
                                <div class="text-danger">{{ form.image.errors }}</div>
                            {% endif %}
                        </div>
                        <div class="form-group">
                            <label for="{{ form.alt_text.id_for_label }}">图片描述</label>
                            {{ form.alt_text }}
                        </div>
                        <div class="form-group form-check">
                            {{ form.is_main }}
                            <label class="form-check-label" for="{{ form.is_main.id_for_label }}">
                                设为主图
                            </label>
                        </div>
                        {% if form.non_field_errors %}
                            <div class="alert alert-danger">{{ form.non_field_errors }}</div>
                        {% endif %}
                        <div class="form-group">
                            <button type="submit" class="btn btn-primary">保存</button>
                            <a href="{% url 'main:product_images' %}" class="btn btn-secondary">取消</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}